package com.lishao.system.security.providers;

import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;

import org.springframework.security.GrantedAuthority;
import org.springframework.security.userdetails.UserDetails;

import com.lishao.soccer.bean.entity.SmUser;

public class SecurityUser implements UserDetails,Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2458612814970808899L;
	private String password;
	private String username;
	private GrantedAuthority[] authorities;
	private boolean accountNonExpired;
	private boolean accountNonLocked;
	private boolean credentialsNonExpired;
	private boolean enabled;
	private SmUser smUser;
	
	public SecurityUser(String paramString1, String paramString2, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, GrantedAuthority[] paramArrayOfGrantedAuthority)
		    throws IllegalArgumentException
    {
	    if ((paramString1 == null) || ("".equals(paramString1)) || (paramString2 == null)) {
	      throw new IllegalArgumentException("Cannot pass null or empty values to constructor");
	    }

	    this.username = paramString1;
	    this.password = paramString2;
	    this.enabled = paramBoolean1;
	    this.accountNonExpired = paramBoolean2;
	    this.credentialsNonExpired = paramBoolean3;
	    this.accountNonLocked = paramBoolean4;
	    setAuthorities(paramArrayOfGrantedAuthority);
    }
	public boolean equals(Object paramObject)
	  {
	    if ((!(paramObject instanceof SecurityUser)) || (paramObject == null)) {
	      return false;
	    }

	    SecurityUser localSecurityUser = (SecurityUser)paramObject;

	    if (localSecurityUser.getAuthorities().length != getAuthorities().length) {
	      return false;
	    }
	    for (int i = 0; i < getAuthorities().length; i++) {
	        if (!getAuthorities()[i].equals(localSecurityUser.getAuthorities()[i])) {
	          return false;
	        }
	    }

	    return (getPassword().equals(localSecurityUser.getPassword())) && (getUsername().equals(localSecurityUser.getUsername())) && 
	      (isAccountNonExpired() == localSecurityUser.isAccountNonExpired()) && 
	      (isAccountNonLocked() == localSecurityUser.isAccountNonLocked()) && 
	      (isCredentialsNonExpired() == localSecurityUser.isCredentialsNonExpired()) && 
	      (isEnabled() == localSecurityUser.isEnabled());
	}
    //������get set����
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public GrantedAuthority[] getAuthorities() {
		return authorities;
	}
	public void setAuthorities(GrantedAuthority[] authorities) {
		this.authorities = authorities;
	}
	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}
	public void setAccountNonExpired(boolean accountNonExpired) {
		this.accountNonExpired = accountNonExpired;
	}
	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}
	public void setAccountNonLocked(boolean accountNonLocked) {
		this.accountNonLocked = accountNonLocked;
	}
	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}
	public void setCredentialsNonExpired(boolean credentialsNonExpired) {
		this.credentialsNonExpired = credentialsNonExpired;
	}
	public boolean isEnabled() {
		return enabled;
	}
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	
	public SmUser getSmUser() {
		return smUser;
	}
	public void setSmUser(SmUser smUser) {
		this.smUser = smUser;
	}
	public String toString() {
	    StringBuffer localStringBuffer = new StringBuffer();
	    localStringBuffer.append(super.toString()).append(": ");
	    localStringBuffer.append("Username: ").append(this.username).append("; ");
	    localStringBuffer.append("Password: [PROTECTED]; ");
	    localStringBuffer.append("Enabled: ").append(this.enabled).append("; ");
	    localStringBuffer.append("AccountNonExpired: ").append(this.accountNonExpired).append("; ");
	    localStringBuffer.append("credentialsNonExpired: ").append(this.credentialsNonExpired).append("; ");
	    localStringBuffer.append("AccountNonLocked: ").append(this.accountNonLocked).append("; ");

	    if (getAuthorities() != null) {
	      localStringBuffer.append("Granted Authorities: ");
	      for (int i = 0; i < getAuthorities().length; i++) {
	          if (i > 0) {
	            localStringBuffer.append(", ");
	          }

	          localStringBuffer.append(getAuthorities()[i].toString());
	      }
	    } else {
	      localStringBuffer.append("Not granted any authorities");
	    }

	    return localStringBuffer.toString();
	  }
}
